<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/scrip.js"></script>

<link rel="stylesheet" type="text/css" href="css/style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Welcome to Software Engineering Project</title>
</head>
<body>
	<div class="master-wrapper-content">
		<jsp:include page="heading.jsp"></jsp:include>
		<jsp:include page="listCategory.jsp"></jsp:include>

		<div class="container-right">
			<%
				String username = (String) session.getAttribute("username");
				User user = dataManager.getUserWithUserName(username);
				List<YourCart> yourCarts = dataManager.getAllCartByUserId(user
						.getUserId());
				int tongtien = 0;
			%>
			<h3>Các sản phầm trong giỏ hàng của bạn</h3>


			<%
				if (yourCarts == null || yourCarts.isEmpty()) {
			%>
			<h3>Bạn chưa chọn sản phẩm nào</h3>
			<%
				} else {
			%>
			<table class="table_product">
				<tr>
					<th>Loại bỏ</th>
					<th>Tên Sản phẩm</th>
					<th>Giá</th>
					<th>Số lượng</th>
					<th>Tổng tiền</th>
				</tr>
				<%
					for (YourCart y : yourCarts) {
							Product p = dataManager.getProductById(y.getProductId());
							tongtien += p.getPrice() * y.getNumber();
				%>

				<tr id="your_cart_item_<%=y.getYourCartId()%>">
					<td><input type="button" value="Xóa"
						onclick="delCartItem(<%=y.getYourCartId()%>)" /></td>
					<td>
						<p><%=p.getProductName()%></p> <a class="img"
						href="productDetail.jsp?productId=<%=p.getProductId()%>"> <img
							src="<%="/ECommerce/DisplayImage?path=" + p.getImage()%>" /></a>
					</td>
					<td><%=p.getPrice()%> dong</td>

					<td><input type="number" size="5"
						id="number_<%=y.getYourCartId()%>" value="<%=y.getNumber()%>"
						onclick="getMoney(<%=p.getPrice()%>, <%=y.getYourCartId()%>)"
						onchange="getMoney(<%=p.getPrice()%>, <%=y.getYourCartId()%>)" /><br>
						<input type="button" value="Cập nhật"
						onclick="updateNumber(<%=y.getYourCartId()%>)" /></td>

					<td id="money_<%=y.getYourCartId()%>"><%=(y.getNumber() * p.getPrice())%>
					</td>

				</tr>

				<%
					}

					}
				%>



			</table>
			<%
				if (!yourCarts.isEmpty()) {
			%>
			<div id="thanhtoan">
				<p>
					Tổng tiền :<span id="totalMoney"> <%=tongtien%></span> <span
						id="status_money">(Da cap nhat)</span>
				</p>
				<form action="updateCart" method="POST">
					<input type="hidden" name="action" value="thanhtoan" /> <input
						type="hidden" name="userId" value="<%=user.getUserId()%>" /> <input
						id="button_thanhtoan" type="submit" value="Thanh Toan" />
				</form>
			</div>
			<%
				}
			%>
		</div>
		<div class="clear"></div>
		<jsp:include page="footer.jsp"></jsp:include>
	</div>
</body>
</html>